package com.example.it_com.common;

import lombok.Data;

/**
 * @author Tom
 */

@Data
public class Result<T> {

    private Integer code;

    private String msg;

    private T data;

    public Result(){}

    /**
     * 中间方法
     * @param data 封装数据
     * @return 数据类型
     * @param <T> 封装数据
     */
    private static <T> Result<T> build(T data) {
        Result<T> result = new Result<T>();
        if (data != null) {
            result.setData(data);
        }
        return result;
    }

    public static <T> Result<T> build(T data, Integer code, String message) {
        Result<T> result = build(data);
        result.setCode(code);
        result.setMsg(message);
        return result;
    }

    public static <T> Result<T> success(T data, String message) {
        Result<T> result = build(data);
        result.setCode(200);
        result.setMsg(message);
        return result;
    }

    public static <T> Result<T> error(T data, String message) {
        Result<T> result = build(data);
        // TODO 记得修改
        result.setCode(500);
        result.setMsg(message);
        return result;
    }


}
